package com.library.service;

import com.library.bean.ReaderCard;
import com.library.dao.AdminDao;
import com.library.dao.ReaderCardDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {

    @Autowired
    private ReaderCardDao readerCardDao;

    @Autowired
    private AdminDao adminDao ;


    public boolean hasMatchReader(String username, String passwd) {

        return readerCardDao.getIdMatchCount(username,passwd)>0;
    }

    public boolean hasMatchAdmin(String username, String passwd) {
        return adminDao.getMatchCount(username,passwd)>0;
    }

    public Long getAdminId(String username) {
        return adminDao.getAdminUsernameId(username);
    }

    public ReaderCard findReaderCardByReaderId(String username) {
        return readerCardDao.findReaderCardByReaderId(username);
    }

    public String getAdminPassword(long id) {
        return adminDao.getPasswd(id);
    }

    public boolean adminRePassword(Long id,String newpasswd) {
        return adminDao.resetPasswd(id, newpasswd)>0;
    }

    public String getReaderPassword(long id) {
        return readerCardDao.getPasswd(id);
    }

    public boolean readerRePassword(long id, String newPasswd) {
        return readerCardDao.resetPasswd(id, newPasswd)>0;
    }
}
